<?php

namespace app\shop\controller\product;

use app\shop\controller\Controller;
use app\shop\model\product\Category as CategoryModel;
use app\shop\model\product\Product as ProductModel;
use app\shop\model\product\RechargeTemp as RechargeTempModel;

/**
 * 商品分类
 */
class RechargeTemp extends Controller
{
    /**
     * 商品分类列表
     */
    public function index()
    {
        // 获取充值模板列表
        $model = new RechargeTempModel;
        $list = $model->getList(array_merge([], $this->postData()));
        return $this->renderSuccess('', compact('list'));
    }

    /**
     * 删除商品分类
     */
    public function remove($recharge_template_id)
    {
        $model = RechargeTempModel::detail($recharge_template_id);
        if ($model->remove($recharge_template_id)) {
            return $this->renderSuccess('删除成功');
        }
        return $this->renderError($model->getError() ?:'删除失败');
    }

    /**
     * 添加商品分类
     */
    public function add()
    {
        $model = new RechargeTempModel;
        // 新增记录
        if ($model->add($this->request->post())) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError($model->getError() ?:'添加失败');
    }

    /**
     * 编辑商品分类
     */
    public function edit($recharge_template_id)
    {
        // 模板详情
        $model = RechargeTempModel::detail($recharge_template_id);
        // 更新记录
        if ($model->edit($this->request->post())) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError($model->getError() ?: '更新失败');
    }

    public function getDict($recharge_template_id)
    {
        $model = new RechargeTempModel;
        $list = $model->getDict($recharge_template_id);
        return $this->renderSuccess('', compact('list'));
    }

}
